package net.alteiar.ui.listener;

import java.awt.event.MouseWheelEvent;

import net.alteiar.ui.ZoomablePanel;
import net.alteiar.ui.condition.DefaultCondition;
import net.alteiar.ui.condition.MouseCondition;

public class ZoomListener extends ConditionMouseAdapter {
	private final ZoomablePanel<?> panel;

	public ZoomListener(ZoomablePanel<?> panel) {
		this(new DefaultCondition(), panel);
	}

	public ZoomListener(MouseCondition condition, ZoomablePanel<?> panel) {
		super(condition);
		this.panel = panel;
	}

	@Override
	protected void realMouseWheelMoved(MouseWheelEvent e) {
		double pas = 0.001;
		if (panel.getZoomFactor() > 1) {
			pas = 0.01;
		}
		for (int i = 0; i < e.getUnitsToScroll(); i++) {
			panel.zoomOut(pas);
		}

		for (int i = 0; i > e.getUnitsToScroll(); i--) {
			panel.zoomIn(pas);
		}
	}
}
